<template>
  <div class="p-2">
    <el-row :gutter="20">
      <el-col :lg="24" :xs="24">
        <div v-show="showSearch" class="mb-[10px]">
          <el-card shadow="hover">
            <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="120">
              <el-form-item label="采样点名称" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入采样点名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </el-card>
        </div>

        <el-card shadow="hover">
          <template #header>
            <el-row :gutter="10">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
              </el-col>
              <right-toolbar v-model:show-search="showSearch" :columns="columns" :search="true" @query-table="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading" border :data="listData" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="50" align="center" />
            <template v-for="(item, index) in columns">
              <el-table-column v-if="item.visible" :key="item.key" :label="item.label" align="center" :prop="item.key" >

              </el-table-column>
            </template>

            <el-table-column label="操作" fixed="right" width="180" class-name="small-padding fixed-width">
              <template #default="scope">
                <el-button link type="primary" icon="Edit" @click="handleEdit">编辑</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            :total="total"
            @pagination="getList"
          />
        </el-card>
      </el-col>
    </el-row>

    <formVue ref="formRef"></formVue>
  </div>
</template>

<script setup>
// 方法
import { ref } from 'vue'
import formVue from '@/views/samplingAdmin/point/form.vue';
const formRef = ref(null)
// 列显隐信息
const columns = ref([
  { key: 'lab1', label: `采样点名称`, visible: true, children: [] },
  { key: 'lab2', label: `采样点地址`, visible: true, children: [] },
  { key: 'lab3', label: `经度`, visible: true, children: [] },
  { key: 'lab4', label: `纬度`, visible: true, children: [] },
  { key: 'lab5', label: `备注`, visible: true, children: [] },
]);

const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
})
const total = ref(0)
const showSearch = ref(true);
const loading = ref(true);
const listData = ref([
  { lab1: '饮水库', lab2: '渝北区龙兴镇', lab3: '39.761523', lab4: '109.13645716', lab5: '渝北区的居民饮水库', },
  { lab1: '污水厂', lab2: '渝北区木耳镇', lab3: '39.34567', lab4: '108.9876543', lab5: '渝北区的居民饮水库', },
]);


// 获取数据
const getList = () => {
  loading.value = false
}

// 搜索
const handleQuery = () => {
}

// 重置
const resetQuery = () => {
  for (let i in queryParams.value) {
    if (i !== 'pageNum' && i !== 'pageSize') {
      queryParams.value[i] = undefined
    }
  }
  handleQuery()
}

// 多选
const handleSelectionChange = () => {
}

// 新增
const handleAdd = () => {
  formRef.value.open()
}
// 编辑
const handleEdit = () => {
  formRef.value.edit()
}


getList()
</script>
